//
//  SplashControllerTwo.m
//  MyCloudMusic
//
//  Created by xiaolong on 2024/4/27.
//

#import "SplashControllerTwo.h"
#import "RegisterController.h"
#import "TestLogicControllerViewController.h"
#import "TermServiceDailogController.h"
#import "DefaultPreferenceUtil.h"
#import "GuideController.h"
@interface SplashControllerTwo ()
@property (nonatomic, strong) TermServiceDailogController *dialogController;
@end

@implementation SplashControllerTwo

- (void)initViews {
    [super initViews];
    
    self.view.backgroundColor = [UIColor whiteColor];
    MyRelativeLayout *container = [MyRelativeLayout new];
    
    container.rightPos.equalTo(@(MyLayoutPos.safeAreaMargin));
    container.leftPos.equalTo(@(MyLayoutPos.safeAreaMargin));
    container.topPos.equalTo(@(MyLayoutPos.safeAreaMargin));
    container.bottomPos.equalTo(@(MyLayoutPos.safeAreaMargin));
    
    [self.view addSubview:container];
    
    
    UIImageView *bannerView = [UIImageView new];
    bannerView.myWidth = 75;
    bannerView.myHeight = 309;
    bannerView.myTop = 120;
    bannerView.myCenterX = 0;
    bannerView.image = [UIImage imageNamed:@"SplashBanner"];
    [container addSubview:bannerView];
    
    UILabel *agrementView = [UILabel new];
    agrementView.myWidth = MyLayoutSize.wrap;
    agrementView.myHeight = 15;
    agrementView.myBottom = 20;
    agrementView.myCenterX = 0;
    agrementView.text = @"Copyright @2019 BoomBoy";
    agrementView.font = [UIFont systemFontOfSize:12];
    agrementView.textColor = [UIColor grayColor];
    [container addSubview:agrementView];
    
    
    UIImageView *logo = [UIImageView new];
    logo.myWidth = 188;
    logo.myHeight = 31;
    logo.bottomPos.equalTo(agrementView.topPos).offset(16);
    logo.myCenterX = 0;
    logo.image = [UIImage imageNamed:@"SplashLogo"];
    logo.contentMode = UIViewContentModeScaleAspectFit;
    [container addSubview:logo];
    
    

}


- (void)initDatum{
    BOOL hasAccept = [DefaultPreferenceUtil isAcceptTermsServiceAgreement];
    
    if(hasAccept){
        GuideController *guide = [GuideController new];
        
        [UIApplication sharedApplication].delegate.window.rootViewController = guide;
        
        
    }
    else{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            RegisterController *controller = [RegisterController new];
            [self.navigationController pushViewController:controller animated:YES];
            NSLog(@"xxxxxxxxxxx");
            
            [self.dialogController show];
        });
    }
    
}




- (TermServiceDailogController *)dialogController{
    if(! _dialogController){
        _dialogController = [TermServiceDailogController new];
        
        _dialogController.titleView.text = R.string.localizable.termServicePrivacy;
        
        [_dialogController.primaryButton addTarget:self action:@selector(priClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _dialogController;
}


- (void)priClicked:(UIButton *)btn{
    [self.dialogController hide];
    [DefaultPreferenceUtil setAeecptTermsServiceAgreement:YES];
}

@end
